#include <util.h>
#include "tusb.h"
#include "ring_buffer.h"
#include "z80_sio.h"

void SIO_Init()
{
}

void SIO_Read(uint8_t addr, uint8_t* out)
{
    if (addr == Z80_SIO_CTRL) {
        // Read SIO I/O buffer status.
        uint8_t status = 0;
        if (tud_cdc_available())       { status |= 0x01; }
        if (tud_cdc_write_available()) { status |= 0x02; }
        *out = status;
    } else if (addr == Z80_SIO_DATA) {
        // Read SIO data.
        *out = tud_cdc_read_char();
    }
}

void SIO_Write(uint8_t addr, const uint8_t* in)
{
    if (addr == Z80_SIO_CTRL) {
        // Write SIO configuration.
        // NOT IMPLEMENTATION
    } else if (addr == Z80_SIO_DATA) {
        // Write SIO data.
        tud_cdc_write_char(*in); 
    }
}
